/*  This file is part of the comicconquer project
    Copyright (C) 2010 Reach <reach334@gmail.com>

    ComicConquer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This software is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public 
    License along with this software.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "CoCheckButton.h"

/**
 * Constructor.
 * 
 * @author reach (5/25/2010)
 * 
 * @param text: Text to display on button.
 * @param parent: Parent widget.
 */
CoCheckButton::CoCheckButton(const QString& text, QWidget* parent)
: ui::OnyxCheckBox(text, parent)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    connect(this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)));

    Out_Log(__FUNCTION__, COCLASSNAME);
}

/**
 * Let this button restrict other widget. Control its enalbe property.
 * 
 * @author reach (5/25/2010)
 * 
 * @param widget: The widget to restrict.
 * @param inverse: For true, the enable property of widget is synchronous with the button. 
 *                 Or it is inverse for true.
 */
void CoCheckButton::restrictOther(QWidget* widget, bool inverse)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    if (inverse)
    {
        connect(this, SIGNAL(restrictInverse(bool)), widget, SLOT(setEnabled(bool)));
    }
    else
    {
        connect(this, SIGNAL(restrict(bool)), widget, SLOT(setEnabled(bool)));
    }

    Out_Log(__FUNCTION__, COCLASSNAME);
}

void CoCheckButton::setChecked(bool checked)
{
    ui::OnyxCheckBox::setChecked(checked);
    emit toggled(checked);
}

void CoCheckButton::onToggled(bool checked)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    emit restrict(checked);
    emit restrictInverse(!checked);

    Out_Log(__FUNCTION__, COCLASSNAME);
}
